package main

import (
	"fmt"
	"os"
	"io"
	"bufio"
)

type CharCount struct {
	chCount int // 记录英文个数
	NumCount int // 记录数字个数
	SpaceCount int // 记录空格个数
	OtherCount int // 记录其他字符个数
}

func main() {

	fileName := "a.txt"
	file, err := os.Open(fileName)
	if err != nil {
		fmt.Println("err:", err)
		return
	}

	defer file.Close()

	var count CharCount
	reader := bufio.NewReader(file)
	for {

		str, err := reader.ReadString('\n')
		if err == io.EOF {
			break
		}

		for _, v := range str {

			switch {

			case v >= 'a' && v <= 'z':
				fallthrough
			case v >= 'A' && v <= 'Z':
				count.chCount++
			case v == ' ' || v == '\t':
				count.SpaceCount++
			case v >= '0' && v <= '9':
				count.NumCount++
			default:
				count.OtherCount++
			}

		}

	}

	fmt.Printf("字符：%v，数字：%v，空格：%v，其他： %v\n", count.chCount, count.NumCount, count.SpaceCount, count.OtherCount)



}